function back() {
    window.location = "addBorrowInfoBackServlet";
}

function check() {
    // const form = document.getElementsByTagName("input")
    // for (let i = 0; i < form.length; i++) {
    //     const value = form[i].value
    //     if (value === "") {
    //         form[i].focus()
    //         return
    //     }
    //
    // }
    // if (isNaN(Number(form[2].value))) {
    //     window.alert("请输入正确的价格！")
    //     form[2].focus()
    //     return
    // }

    document.getElementById("addForm").submit()
}

function showauto(){
    $('.auto-complete').show();
    // console.log("onfocus");
}

function hideauto(){
    $('.auto-complete').hide();
    // console.log("onblur");
}

function keyupauto(){
    var key =  $('#inputBookname').val();
    // console.log('key: ' + key);
    if(key !== '' && key !== null && key.trim().length > 0){
        $.ajax({
            url : 'SearchBookNameByKeyServlet?key=' + key,
            type : 'GET',
            success : function (data){
                var liHTML = '';
                for (var i = 0; i < data.length; i++) {
                    liHTML += '<li class=\"borrowli\" date-name=\"';
                    liHTML += data[i];
                    liHTML += '\">'
                    liHTML += data[i];
                    liHTML += '</li>';
                }
                $('.auto-complete-ul').html(liHTML);
                if(data !== null && data !== '')
                    $('.auto-complete').show();
            },
            error : function (msg){
                console.log(msg);
            }
        });

    }else{
        $('.auto-complete').hide();
    }
}

$(function() {
    $('#auto-complete-ul').on('mouseenter', '.borrowli', function (event){
        console.log('l:' + $(this).text());
        $('#inputBookname').val($(this).text())
        ;
    });

    $('#returndate').on('blur', function (){
        var date1 = $('#borrowdate').val(),
            date2 = $('#returndate').val();
        if(date1.localeCompare(date2) > 0){
            var s = 'Invalid!';
            $('#returndatemsg').text(s);
        }else{
            $('#returndatemsg').text('');
        }
    });
});